/*
 *  $TEAM_NAME Space Trader
 */
package models;

import java.util.Observable;

/**
 * The class Encounter represents a random encounter within space trader
 * @author bradley
 * @version 1.0
 */
public class Encounter extends Observable {
	/**
	 * 90
	 */
	private static final double NINTY = .90;
	
	/**
	 * 2
	 */
	private static final int TWO = 2;
	
	/**
	 * field
	 */
	private final Type type;
	
	/**
	 * field
	 */
	private Character character;
	
	/**
	 * field
	 */
	private Player player;
	
	/**
	 * Creates a generic encounter
	 */
	public Encounter(){
		this.type = null;
	}
	
	/**
	 * Creates a new encounter of type
	 * @param type the type of encounter
	 * @param player the player
	 */
	public Encounter(Type type, Player player){
		this.type = Type.PIRATE;
		this.player = player;
		if(type == Type.PIRATE){
			this.character = new Pirate();
		}
	}
	
	/**
	 * @return the player
	 */
	public Player getPlayer() {
		return player;
	}

	/**
	 * @param player the player to set
	 */
	public void setPlayer(Player player) {
		this.player = player;
	}

	/**
	 * Gets the type of encounter
	 * @return type
	 */
	public Type getType(){
		return this.type;
	}
	
	/**
	 * Gets the character the encounter is with
	 * @return the character
	 */
	public Character getCharacter(){
		return this.character;
	}
	
	/**
	 * Sets the character
	 * @param character
	 */
	public void setCharacter(Character character){
		this.character = character;
	}
	
	/**
	 * Randomizes if an encounter occurs
	 * @return true if encounter occurs
	 */
	public static boolean isOccuring(){
		if(Math.random() > NINTY){
			return true;
		}
		return false;
	}
	
	/**
	 * Types of encounters available
	 * @author bradley
	 * @version 1.0
	 */
	public enum Type{
		PIRATE
	}
	
	/**
	 * The class pirate represents a pirate in an encounter in space trader
	 * @author bradley
	 * @version 1.0
	 */
	public class Pirate extends Character{
		/**
		 * field
		 */
		private Ship ship;
		
		/**
		 * Creates a new pirate
		 */
		public Pirate(){
			super("Pirate", TWO, TWO, TWO, TWO);
			this.ship = Ship.gnat();
			this.ship.canAddWeapon(Weapon.beamLaser());
			super.setCharacterActions(Actions.ATTACK, Actions.FLEE);
			super.setPlayerActions(Actions.ATTACK, Actions.FLEE, Actions.SURRENDER);
		}
		
		/**
		 * attacks
		 * @return attack
		 */
		@Override
		public int attack(){
			return ship.attack();
		}
		
		/**
		 * defends
		 * @param attack
		 */
		@Override
		public void defend(int attack){
			this.ship.defend(attack);
		}
		
		/**
		 * Setter for ship
		 * @param ship - the ship to set
		 */
		public void setShip(Ship ship){
			this.ship = ship;
		}
		
		/**
		 * Getter for ship
		 * @return - the ship
		 */
		public Ship getShip(){
			return this.ship;
		}
		
		/**
		 * to string
		 * @return string
		 */
		@Override
		public String toString() {
			return "";
		}
	}

	/**
	 * to string
	 * @return string
	 */
	public String toString() {
		return "";
	}
}
